package com.dheaven.framework.core.dwrmvc;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeansException;
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;

public class DwrHandlerMapping extends SimpleUrlHandlerMapping {

	protected static final Log log = LogFactory.getLog(DwrHandlerMapping.class);

	public void initApplicationContext() throws BeansException {
		Object handler = getApplicationContext().getBean("dwrController");
		Map<String, Object> mappings = new HashMap<String, Object>();
		mappings.put("/engine.js", handler);
		mappings.put("/util.js", handler);
		mappings.put("/interface/**", handler);
		mappings.put("/call/**", handler);
		if (log.isDebugEnabled())
		{
			log.debug("[engine.js] mapped to dwrController");
			log.debug("[util.js] mapped to dwrController");
			log.debug("Interface beans and calls mapped to dwrController");
		}
		setUrlMap(mappings);
		super.initApplicationContext();
	}

}
